import { createApp } from 'vue'
import './style.css'
import App from './App.vue'
import router from './router'
import { createPinia } from 'pinia'
// import "lib-flexible/flexible"

router.beforeEach((to, from) => {
  const token = localStorage.getItem('pz_token')
  // 非登陆页面token不存在
  if (!token && to.path !== '/login') {
    return '/login'
  } else if (token && to.path == '/login') {
    return '/'
  } else {
    return true
  }
})

import * as ElementPlusIconsVue from '@element-plus/icons-vue'



const pinia = createPinia()
const app = createApp(App)
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component)
}

app.use(router)//路由挂载 顺序1
app.use(pinia)
app.mount('#app')//应用挂载 顺序2